<?php
/**
 * UserModel
 */
class Application_Models_UserModel{
    private $_idUser;
    private $_password;
    private $_userType;
    
    function __construct() {
        
    }

    public function get_idUser() {
        return $this->_idUser;
    }

    public function set_idUser($_idUser) {
        $this->_idUser = $_idUser;
    }

    public function get_password() {
        return $this->_password;
    }

    public function set_password($_password) {
        $this->_password = $_password;
    }

    public function get_userType() {
        return $this->_userType;
    }

    public function set_userType($_userType) {
        $this->_userType = $_userType;
    }
    
    public function validateUser(){
        global $config;
        $objDb=new Class_Db();
        $objDb->selectManager()->connect();
        $query="SELECT tipo_usuario FROM usuario 
            WHERE usuario='".$this->get_idUser()."' AND clave='".$this->get_password()."'";
        //die("consulta->".$query);
        $consult=$objDb->selectManager()->select($query);        
        //die("---".$consult[0][0]."----".$config['typeUserAdmin']);
        if($consult[0][0]==$config['typeUserAdmin']){
            if (!$_SESSION) {
                session_start();
                $_SESSION['user']=  $this->get_idUser();
                $_SESSION['level']= $consult[0][0];
                header("Location: index.php");
            }else{
                session_destroy();
            }            
        }else{
            header("Location: login");
        }
        
    }
    public function closeSession(){
        session_start();
        if($_SESSION){
            session_destroy();
            header("Location: login");
        }else{
            header("Location: login");
        }
    }


}

